﻿using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using ProtoBuf.Message;

namespace UI
{
    public class UICopyRunMapBox : MonoBehaviour
    {
        public GameObject commomIcon;
        public UIGrid grid;

        List<GameObject> list = new List<GameObject>();
        List<BaseResource> baseResources = new List<BaseResource>();
        //bool canGet = false;

        public void Init(List<BaseResource> baseResources)
        {
            //this.canGet = canGet;
            this.baseResources.Clear();
            this.baseResources.AddRange(baseResources);
            StopAllCoroutines();
            StartCoroutine(_init());
        }

        IEnumerator _init()
        {
            foreach (var obj in list)
            {
                GameObject.Destroy(obj);
            }
            list.Clear();
            yield return null;
            foreach(var it in baseResources)
            {
                GameObject inst = GameObject.Instantiate(commomIcon);
                inst.transform.SetParent(grid.transform);
                inst.transform.localScale = Vector3.one;
                var script = inst.GetComponent<CommonIcon>();
                script.SetData(it.id, false,it.num);
                grid.Reposition();
                list.Add(inst);
            }
            //grid.Reposition();
        }

        public void OnClick()
        {
            gameObject.SetActive(false);
        }
    }
}
